import request from '@/utils/request'
import { kke } from '@/utils/rsaEncrypt'

export function add(data) {
  return request({
    url: 'admin/auth/add',
    method: 'post',
    data
  })
}

export function del(ids) {
  return request({
    url: 'admin/auth/delete',
    method: 'delete',
    data: ids
  })
}

export function edit(data) {
  return request({
    url: 'admin/auth/update',
    method: 'put',
    data
  })
}

export function updateStatus(data) {
  return request({
    url: 'admin/auth/updateStatus',
    method: 'post',
    data
  })
}

export function editUser(user) {
  const data = user
  if (user.newPassword !== null && user.newPassword !== '') {
    data.oldPassword = kke('admin', user.oldPassword)
    data.newPassword = kke('admin', user.newPassword)
  } else {
    data.oldPassword = null
    data.newPassword = null
  }
  return request({
    url: 'admin/auth/modify',
    method: 'put',
    data
  })
}

export function getDepartList(params) {
  return request({
    url: 'admin/common/department/list',
    method: 'get',
    params
  })
}

export default { add, edit, del }

